package com.mhz.widgets.client.filtertextbox;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mhz.widgets.client.filtertextbox.Filter.RemoveFilterHandler;

public class FilterTextBox extends Composite {

	@UiTemplate("FilterTextBox.ui.xml")
	interface ViewUiBinder extends UiBinder<Widget, FilterTextBox> {
	}

	private static ViewUiBinder uiBinder = GWT.create(ViewUiBinder.class);

	@UiField
	HTMLPanel textbox;
	@UiField
	HorizontalPanel textboxFilters;
	@UiField
	DivElement textboxContent;

	RemoveFilterHandler handler;

	public FilterTextBox() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public void addFilter(String filterName) {
		Filter filter = new Filter(filterName);
		filter.setRemoveFilterHandler(handler);
		textboxFilters.add(filter);
	}

	public void removeAllFilters() {
		textboxFilters.clear();
	}

	public void setRemoveFilterHandler(RemoveFilterHandler handler) {
		this.handler = handler;
	}

}
